#include "settingswindow.h"
#include "ui_settingswindow.h"
#include <QFileDialog>
#include "../../core/settings.h"

SettingsWindow::SettingsWindow(QDialog *parent) :
    QDialog(parent),
    ui(new Ui::SettingsWindow)
{
    ui->setupUi(this);
    this->setFixedSize(this->size());

    //settings.setPath(QSettings::IniFormat,QSettings::UserScope,"ShotScreensUploader.ini");

    connect(ui->chooseButton, SIGNAL(clicked()), SLOT(onChooseButtonClicked()));
    connect(ui->buttonBox->buttons().at(0), SIGNAL(clicked()), SLOT(onOkButtonClicked())); // ...->buttons().at(0) - I think, there is a better way to do it...
    connect(ui->buttonBox->buttons().at(1), SIGNAL(clicked()), SLOT(onCancelButtonClicked()));
}

SettingsWindow::~SettingsWindow()
{
    delete ui;
}

void SettingsWindow::setDefaultDir(QString &dir)
{
    ui->dirLineEdit->setText(dir);
}

void SettingsWindow::onChooseButtonClicked()
{
    ui->dirLineEdit->setText(QFileDialog::getExistingDirectory(0, tr("Open Directory"), ".", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks));
}

void SettingsWindow::onOkButtonClicked()
{
    //settings.setValue("DefaultDir", ui->dirLineEdit->text()); // delete it.
    Settings::instance().setValue("DefaultDir", ui->dirLineEdit->text());
    this->parentWidget()->close();
}

void SettingsWindow::onCancelButtonClicked()
{
    this->parentWidget()->close();
}

QSize SettingsWindow::minSize() const
{
    return ui->gridLayout->sizeHint() + ui->buttonBox->sizeHint() + QSize(-50, 30);
}
